package com.ham.common;

import java.io.IOException;
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.SQLException;
import java.util.Properties;

public class DBConn {

	private Connection conn;

	private DBConn() {
		try {
			this.conn = getConnection();
		} catch (ClassNotFoundException e) {
			e.printStackTrace();
		} catch (SQLException e) {
			e.printStackTrace();
		} catch (IOException e) {
			e.printStackTrace();
		}
	}

	public static DBConn getInstance() {
		return new DBConn();
	}

	private static Connection getConnection() throws ClassNotFoundException,
			SQLException, IOException {
		Properties prop = new Properties();
		prop.load(DBConn.class.getClass().getResourceAsStream(
				"/config.properties"));

		Class.forName(prop.getProperty("jdbc.driver"));
		return DriverManager.getConnection(prop.getProperty("db.url"),
				prop.getProperty("db.user"), prop.getProperty("db.password"));
	}

	public Connection connect() {
		return conn;
	}

}
